package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import java.util.List;

import flc.ast.R;
import flc.ast.bean.MyCollectBean;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class CollectAdapter extends StkProviderMultiAdapter<MyCollectBean> {


    public CollectAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new CollectProvider());
    }

    private boolean isManage;

    public void setManage(boolean manage) {
        isManage = manage;
        notifyDataSetChanged();
    }

    private class CollectProvider extends BaseItemProvider<MyCollectBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_sel_pic;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyCollectBean bean) {
            Glide.with(getContext()).load(bean.getPath()).into((ImageView) baseViewHolder.getView(R.id.ivSelPicItemImg));
            if (isManage) {
                baseViewHolder.getView(R.id.ivSelPicItemSel).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivSelPicItemCollect).setVisibility(View.GONE);
                if (bean.isSelected()) {
                    baseViewHolder.setImageResource(R.id.ivSelPicItemSel, R.drawable.icon_gx2);
                } else {
                    baseViewHolder.setImageResource(R.id.ivSelPicItemSel, R.drawable.icon_gx1);
                }
            } else {
                baseViewHolder.getView(R.id.ivSelPicItemSel).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivSelPicItemCollect).setVisibility(View.VISIBLE);
            }
        }
    }

}
